package com.mate.cloud.redisson.controller;

import com.mate.cloud.protocol.response.BaseResponse;
import com.mate.cloud.protocol.web.controller.AdminBaseController;

import com.mate.cloud.redisson.dto.Product;
import com.mate.cloud.redisson.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Set;

/**
 * 接口性能优化案例
 *
 * @author: MI
 * @email: 448341911@qq.com
 * @createTime: 2025/9/12 18:35
 * @updateUser: MI
 * @updateTime: 2025/9/12 18:35
 * @updateRemark: 修改内容
 * @version: 1.0
 */
@RestController
public class ProductController extends AdminBaseController {


    @Autowired
    private ProductService productService;

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public BaseResponse<List<Product>> selectProduct() {
        return successBodyResponse(productService.selectProduct());
    }

    @RequestMapping(value = "/id", method = RequestMethod.GET)
    public BaseResponse<Long> getId() {
        return successBodyResponse(productService.getId());
    }


    @RequestMapping(value = "/pay", method = RequestMethod.GET)
    public BaseResponse<String> pay(@RequestParam("id") Long id) throws InterruptedException {
        return successBodyResponse(productService.pay(id));
    }

    @RequestMapping(value = "/pay_lock", method = RequestMethod.GET)
    public BaseResponse<String> payRedisson(@RequestParam("id") Long id) throws InterruptedException {
        return successBodyResponse(productService.payRedisson(id));
    }

    @RequestMapping(value = "/pay_multi", method = RequestMethod.GET)
    public BaseResponse<String> payMultiLock(@RequestParam("id") Long id) throws InterruptedException {
        return successBodyResponse(productService.payMultiLock(id));
    }

//    @RequestMapping(value = "/statistic",method = RequestMethod.GET)
//
//    public ProductStatics statistic(@RequestParam("id") Integer id)  {
//        return productService.getStatics(id);
//    }

    @RequestMapping(value = "/pv", method = RequestMethod.GET)
    public BaseResponse<Integer> addPv(@RequestParam("id") Integer id) {
        return successBodyResponse(productService.addPv(id));
    }

    @RequestMapping(value = "/uv", method = RequestMethod.GET)
    public BaseResponse<Integer> addUv(@RequestParam("id") Integer id) {
        return successBodyResponse(productService.adduv(id));
    }

    @RequestMapping(value = "/rank_init", method = RequestMethod.GET)
    public void rankInit() {
        productService.rankInit();
    }


    @RequestMapping(value = "/rank", method = RequestMethod.GET)
    public BaseResponse<Set> rank() {
        return successBodyResponse(productService.rank());
    }

    @RequestMapping(value = "/test", method = RequestMethod.GET)
    public BaseResponse<Long> test() {
        return successBodyResponse(productService.test());
    }

    @RequestMapping(value = "/test1", method = RequestMethod.GET)
    public BaseResponse<Long> test1() {
        return successBodyResponse(productService.test1());
    }

}
